package de.geckocraft.iConomyExchange.main;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;

public class ExServer
{
	public String name;
	public String Balancetabellenname;
	public String Accounttabellenname;
	public HashMap<String, Double> wechselkurs;
	public String databaspfad;
	public String databaseuser;
	public String databasepw;
	public Connection con = null;
	public Statement stmt = null;
	static ResultSet rs = null;
	public String waehrung;

	ExServer(String uname, String uBalancetabellenname, String uAccounttabellenname,
			HashMap<String, Double> uwechselkurs, String udatabaspfad,
			String udatabaseuser, String udatabasepw, String uwaehrung)
	{
		name = uname;
		Balancetabellenname = uBalancetabellenname;
		Accounttabellenname = uAccounttabellenname;
		wechselkurs = uwechselkurs;
		databaspfad = udatabaspfad;
		databaseuser = udatabaseuser;
		databasepw = udatabasepw;
		waehrung = uwaehrung;

		connect();

	}

	public void connect()
	{
		try
		{
			con = DriverManager.getConnection(databaspfad, databaseuser,
					databasepw);
			stmt = con.createStatement();
		} catch (SQLException e)
		{
			System.out
					.println("[iConomyExchange]Kann mich nicht mit der Datenbank von "
							+ name + " verbinden.");
			System.out.println(databaspfad+","+ databaseuser+","+
					databasepw);
		}

	}

	public ResultSet sendStatement(String statement)
	{
		rs = null;
		try
		{
			System.out.println(statement);
			rs = stmt.executeQuery(statement);
		} catch (SQLException e)
		{

		}

		return rs;
	}

	public void sendUpdate(String statement)
	{
		try
		{
			System.out.println(statement);
			stmt.executeUpdate(statement);
		} catch (SQLException e)
		{

		}
	}

	public String getName()
	{
		return name;
	}

	public String getBalancetabellenname()
	{
		return Balancetabellenname;
	}
	
	public String getAccounttabellenname()
	{
		return Accounttabellenname;
	}

	public HashMap<String, Double> getWechselkurs()
	{
		return wechselkurs;
	}

	public String getWaehrung()
	{
		return waehrung;
	}
}
